package cn.wubo.hello.controller;

import cn.wubo.hello.entity.Hello;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String hello(){
        return "Hello,World!";
    }

    private static final String template = "Hello，%s，现在是%tc！";
    //线程安全的记数类
    private final AtomicLong counter = new AtomicLong();

    /**
     * helloSomeOne
     * @param name 设置默认值World
     * @return 结果集c
     */
    @RequestMapping("/helloSomeOne")
    public Hello greeting(@RequestParam(value="name", defaultValue="World") String name) {
        //String.format(format,args...)字串符格式化
        return new Hello(counter.incrementAndGet(),
                String.format(template, name, new Date()));
    }
}
